package com.qianfeng.libra.cowshop.app.activities.home;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
import com.qianfeng.libra.cowshop.app.R;
import com.qianfeng.libra.cowshop.app.activities.LoginActivity;
import com.qianfeng.libra.cowshop.app.activities.ProductDetailActivity;
import com.qianfeng.libra.cowshop.app.models.SpecialSubject;
import com.qianfeng.libra.cowshop.app.models.SubItem;
import com.qianfeng.libra.cowshop.app.models.TopicProduct;
import com.qianfeng.libra.cowshop.app.tasks.DownloadDataTask;
import com.qianfeng.libra.cowshop.app.tasks.TaskProcessor;
import com.qianfeng.libra.cowshop.app.utils.Contacts;
import com.viewpagerindicator.TabPageIndicator;
import org.json.JSONObject;

import java.util.List;


public class MainActivity extends FragmentActivity implements TaskProcessor, View.OnClickListener {
    private static final String[] titleNames = {"首页","特卖", "手机", "电子", "家用",
            "食品", "美妆", "新奇", "美酒"};
    private static final String[] urls = {Contacts.MAIN_URL, Contacts.TEMAI_URL, Contacts.MOBILE_URL,
            Contacts.ELECTRIC_URL, Contacts.HOME_URL, Contacts.FOOD_URL,
            Contacts.MEIZHUANG_URL, Contacts.XINQI_URL, Contacts.DRINK_URL};
    private static final String TAG = "MainActivity";
    private ViewPager pager;
    private TabPageIndicator indicator;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        pager = (ViewPager) findViewById(R.id.activity_main_pager);
        indicator = (TabPageIndicator) findViewById(R.id.activity_main_indicator);
        ImageView imageView=(ImageView)findViewById(R.id.bottom_button_2);
        imageView.setOnClickListener(this);
//        indicator.setViewPager(pager);

        DownloadDataTask task = new DownloadDataTask(this);
        task.execute(Contacts.SPECIAL_SUBJECT_URL);
    }



    public void btnShowDetail(View v){
        TopicProduct topicProduct = new TopicProduct();
        topicProduct.setProductSN("90000044");
        topicProduct.setQHMProductSN("507");
        topicProduct.setQHMSaleProductSN("515");
        topicProduct.setTitle("【牛败自营】外星人 ALW17ER-1728 17英寸游戏本（i7-4710HQ 16G 1TB+512G SSD GTX 980M 4G独显 Win8）");
        topicProduct.setImageSN("http://image.it168.com/Images/QHMImage/QHMProductImageIT168/170x170/0/5/5317.jpg");
        topicProduct.setPrice(20999);
        topicProduct.setEbbPrice(21999);
        topicProduct.setShortPrice(1000);
        topicProduct.setStock("5");
        topicProduct.setSaleTime("2015/3/20 16:11:15");
        topicProduct.setStopSaleTime("2015/5/1 16:11:15");
        topicProduct.setSort("1");
        topicProduct.setIsTop("True");
        topicProduct.setWebSiteLogo("http://image.it168.com/Images/EBMobileWebImage/66/66.jpg");
        topicProduct.setLimitSaleNum("1");
        Intent intent = new Intent(this, ProductDetailActivity.class);
        intent.putExtra("TopicProduct",topicProduct);
        startActivity(intent);
    }
    public void btnLogin(View view)
    {
        Intent intent = new Intent(this, LoginActivity.class);
        startActivity(intent);
    }


    @Override
    public void processResult(JSONObject result) {
        if (result != null){
            SpecialSubject specialSubject = new SpecialSubject();
            specialSubject.parseJson(result);
            List<SubItem> list = specialSubject.getList();
            if (list != null){

            }
        }
    }

    @Override
    public void onClick(View v) {
        Intent intent=new Intent(this,LoginActivity.class);
        startActivity(intent);
    }
}
